﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace Models
{
    /// <summary>
    /// 树节点数据
    /// </summary>
    public class TreeNodeData : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private bool _IsVisible = true;
        /// <summary>
        /// 是否可见
        /// </summary>
        public bool IsVisible
        {
            get
            {
                return _IsVisible;
            }
            set
            {
                _IsVisible = value;
                OnPropertyChanged("IsVisible");
            }
        }

        private bool _IsSelected = false;
        /// <summary>
        /// 是否已选择
        /// </summary>
        public bool IsSelected
        {
            get
            {
                return _IsSelected;
            }
            set
            {
                _IsSelected = value;
                OnPropertyChanged("IsSelected");
            }
        }

        private bool _IsLoading = false;
        /// <summary>
        /// 是否正在加载子节点
        /// </summary>
        public bool IsLoading
        {
            get
            {
                return _IsLoading;
            }
            set
            {
                _IsLoading = value;
                OnPropertyChanged("IsLoading");
            }
        }

        private bool _IsChildLoaded = false;
        /// <summary>
        /// 子节点是否已加载完毕
        /// </summary>
        public bool IsChildLoaded
        {
            get
            {
                return _IsChildLoaded;
            }
            set
            {
                _IsChildLoaded = value;
                OnPropertyChanged("IsChildLoaded");
            }
        }

        private bool _IsLeaf = false;
        /// <summary>
        /// 是否是叶子节点
        /// </summary>
        public bool IsLeaf
        {
            get
            {
                return _IsLeaf;
            }
            set
            {
                _IsLeaf = value;
                OnPropertyChanged("IsLeaf");
            }
        }

        private bool _IsCheckable = false;
        /// <summary>
        /// 是否显示CheckBox
        /// </summary>
        public bool IsCheckable
        {
            get
            {
                return _IsCheckable;
            }
            set
            {
                _IsCheckable = value;
                OnPropertyChanged("IsCheckable");
            }
        }

        private bool _IsExpanded = false;
        /// <summary>
        /// 是否展开
        /// </summary>
        public bool IsExpanded
        {
            get
            {
                return _IsExpanded;
            }
            set
            {
                _IsExpanded = value;
                OnPropertyChanged("IsExpanded");
            }
        }

        private TreeNodeData _parent;
        /// <summary>
        /// 父节点数据
        /// </summary>
        public TreeNodeData Parent
        {
            get
            {
                return _parent;
            }
            set
            {
                _parent = value;
                OnPropertyChanged("Parent");
            }
        }

        private ObservableCollection<TreeNodeData> _children = new ObservableCollection<TreeNodeData>();
        /// <summary>
        /// 子节点数据集合
        /// </summary>
        public ObservableCollection<TreeNodeData> Children
        {
            get
            {
                return _children;
            }
            set
            {
                _children = value;
                OnPropertyChanged("Parent");
            }
        }

        private int _PageSize = 25;
        /// <summary>
        /// 每页数据条数
        /// </summary>
        public int PageSize
        {
            get
            {
                return _PageSize;
            }
            set
            {
                _PageSize = value;
                OnPropertyChanged("PageSize");
            }
        }

        private bool _SearchMode = false;
        /// <summary>
        /// 搜索模式
        /// </summary>
        public bool SearchMode
        {
            get
            {
                return _SearchMode;
            }
            set
            {
                _SearchMode = value;
                OnPropertyChanged("SearchMode");
                OnPropertyChanged("PageCtrlVisible");
            }
        }

        /// <summary>
        /// 是否显示分页控件
        /// </summary>
        public Visibility PageCtrlVisible
        {
            get
            {
                if (!SearchMode && IsOrgLeaf && CameraCount > 0)
                {
                    return Visibility.Visible;
                }
                return Visibility.Collapsed;
            }
        }

        /// <summary>
        /// 是否显示展开按钮
        /// </summary>
        public Visibility ExpandVisible
        {
            get
            {
                if (IsOrgLeaf)
                {
                    if (CameraCount > 0)
                    {
                        return Visibility.Visible;
                    }
                    else
                    {
                        return Visibility.Hidden;
                    }
                }
                else
                {
                    if (Children.Count > 0)
                    {
                        return Visibility.Visible;
                    }
                    else
                    {
                        return Visibility.Hidden;
                    }
                }
            }
        }

        private bool _IsOrgLeaf = false;
        /// <summary>
        /// 是否是组织机构叶子节点
        /// </summary>
        public bool IsOrgLeaf
        {
            get
            {
                return _IsOrgLeaf;
            }
            set
            {
                _IsOrgLeaf = value;
                OnPropertyChanged("IsOrgLeaf");
            }
        }

        private string _level;
        /// <summary>
        /// 组织机构等级
        /// </summary>
        public string Level
        {
            get
            {
                return _level;
            }
            set
            {
                _level = value;
                OnPropertyChanged("Level");
            }
        }

        private bool _IsOnline = true;
        /// <summary>
        /// 像机是否在线
        /// </summary>
        public bool IsOnline
        {
            get
            {
                return _IsOnline;
            }
            set
            {
                _IsOnline = value;
                OnPropertyChanged("IsOnline");
            }
        }

        private List<TreeNodeData<PtCameraInfo>> _cameraNodeDataList = new List<TreeNodeData<PtCameraInfo>>();
        /// <summary>
        /// 该节点下摄像机集合
        /// </summary>
        public List<TreeNodeData<PtCameraInfo>> CameraNodeDataList
        {
            get
            {
                return _cameraNodeDataList;
            }
            set
            {
                _cameraNodeDataList = value;
            }
        }

        private int _CameraCount;
        /// <summary>
        /// 该节点下像机总数
        /// </summary>
        public int CameraCount
        {
            get
            {
                return _CameraCount;
            }
            set
            {
                _CameraCount = value;
                OnPropertyChanged("CameraCount");

                CameraCountString = string.Format("({0}/{1})", OnlineCameraCount, CameraCount);
            }
        }

        private int _OnlineCameraCount;
        /// <summary>
        /// 该节点下在线像机总数
        /// </summary>
        public int OnlineCameraCount
        {
            get
            {
                return _OnlineCameraCount;
            }
            set
            {
                _OnlineCameraCount = value;
                OnPropertyChanged("OnlineCameraCount");

                CameraCountString = string.Format("({0}/{1})", OnlineCameraCount, CameraCount);
            }
        }

        private string _CameraCountString;
        /// <summary>
        /// 该节点下像机总数String
        /// </summary>
        public string CameraCountString
        {
            get
            {
                return _CameraCountString;
            }
            set
            {
                _CameraCountString = value;
                OnPropertyChanged("CameraCountString");
            }
        }

        /// <summary>
        /// 树节点数据 构造函数
        /// </summary>
        public TreeNodeData()
        {

        }

        protected void OnPropertyChanged(string name)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }
    }
}
